#include<iostream>
using namespace std;

void Gauss_without(double *A,double *b,int n);

void Gauss_without(double *A,double *b,int n)
{
    double x[n],a,c;
    int i,j,k;

    for(i=0;i<n;i++)
    x[i]=0;
    //消去过程
    for(k=0;k<n-1;k++)
	{
		if(!(*(A+k*n+k)))
		return -1;
		for(i=k+1;i<n;i++)
		{
			a=(*(A+i*n+k))/(*(A+K*n+k));
			for(j=k;j<n;j++)
			{
				*(A+i*n+j)=*(A+i*n+j)-a*(*(A+k*n+j));
			}
			b[i]=b[i]-a*b[k];
		}
	} 
	//消去结果
	 cout<<"U="<<endl;
	 for(i=0;i<n;i++)
	 {
	   for(j=0;j<n;j++)
	     cout<<*(A+i*n+j)<<" ";
	 cout<<endl;
	 }
	 //回代法求解
	 x[n-1]=b[n-1]/(*(A+(n-1)*n+n-1));
	 for(k=n-2;k>=0;k--)
	 {
	 	c=b[k];
	 	for(j=k+1;j<n;j++)
	 	{
	 		c=c-(*(A+k*n+j))*x[j];
	 	}
	 	x[k]=c/(*(A+k*n+k));
	 } 
	 //result
	 cout<<"x="<<endl;
	 for(i=0;i<n;i++)
	 cout<<x[i]<<"  ";
	 cout<<endl; 
}